import 'package:base_library/base_library.dart';
import 'package:flutter/material.dart';
import 'package:fluintl/fluintl.dart';
import 'package:wan_android_flutter/res/Ids.dart';

import 'home_page.dart';
import 'home_page2.dart';
import 'home_page3.dart';
import 'home_page4.dart';

class _Pages {
  final String labelId;

  _Pages(this.labelId);
}

final List<_Pages> _pages = <_Pages>[
  new _Pages('主页'),
  new _Pages('项目'),
  new _Pages('动态'),
  new _Pages('体系'),
];

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: _pages.length,
      child: Scaffold(
        appBar: MyAppBar(
          leading: Image(
            image: AssetImage(Util.getImgPath('ali_connors')),
          ),
          centerTitle: true,
          title: TabLayout(),
          actions: <Widget>[
            IconButton(icon: Icon(Icons.search), onPressed: null)
          ],
        ),
        body: TabBarViewLayout(),
      ),
    );
  }
}

class TabLayout extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return TabBar(
      isScrollable: true,
      labelPadding: EdgeInsets.all(12.0),
      indicatorSize: TabBarIndicatorSize.label,
      tabs: _pages.map((_Pages page) => new Tab(text: page.labelId)).toList(),
    );
  }
}

class TabBarViewLayout extends StatelessWidget {
  Widget buildTabView(BuildContext context, _Pages page) {
    String labelId = page.labelId;
    switch (labelId) {
      case '主页':
        return HomePage1(title: labelId);
        break;
      case '项目':
        return HomePage2(title: labelId);
        break;
      case '动态':
        return HomePage3(title: labelId);
        break;
      case '体系':
        return HomePage4(title: labelId);
        break;
      default:
        return Container();
        break;
    }
  }

  @override
  Widget build(BuildContext context) {
    LogUtil.e("TabBarViewLayout build.......");
    return new TabBarView(
        children:
            _pages.map((_Pages page) => buildTabView(context, page)).toList());
  }
}
